package com.bc.bcapi.service;

import com.bc.bcmodel.req.CommReq;
import com.bc.bcmodel.resp.AccountLogInfoResp;
import com.bc.commoncore.util.CookieUtils;
import com.bc.commoncore.util.StringUtils;
import com.bc.commonentity.common.JsonResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.math.BigInteger;

import com.bc.bcapi.dao.T_Account_logMapper;
import com.bc.bcmodel.domain.T_Account_logModel;
import com.bc.bcmodel.consts.MultiLanguage;

/**
 * @Name T_Account_logService * @Description TODO * @Author generation * @Date 2018/8/14 15:26:22 * @Version 1.0
 **/
@Service
public class T_Account_logService {
    @Resource
    T_Account_logMapper t_Account_logMapper;

    /**
     * 保存单条数据     *      * @return
     */
    public int insert(T_Account_logModel req) {
        return t_Account_logMapper.insert(req);
    }

    /**
     * 批量增加数据     *      * @return
     */

    public int insertBatch(List<T_Account_logModel> req) {
        return t_Account_logMapper.insertBatch(req);
    }

    /**
     * 根据对象属性查找满足条件的第一条数据     *      * @return
     */

    public T_Account_logModel findByNamedParam(T_Account_logModel req) {
        return t_Account_logMapper.findByNamedParam(req);
    }

    /**
     * 根据对象查询所有数据     *      * @return
     */

    public List<T_Account_logModel> getAllList(T_Account_logModel req) {
        return t_Account_logMapper.findByNamedParamList(req);
    }

    /**
     * 根据对象查询所有分页数据     *      * @return
     */

    public PageInfo<T_Account_logModel> getList(T_Account_logModel req) {
        PageHelper.startPage(req.getPage_index(), req.getPage_size());
        List<T_Account_logModel> list = t_Account_logMapper.findByNamedParamList(req);
        return new PageInfo<T_Account_logModel>(list);
    }

    /**
     * 更新指定对象     *      * @return
     */

    public int update(T_Account_logModel req) {
        return t_Account_logMapper.update(req);
    }

    /**
     * 删除指定数据     *      * @return
     */

    public int delete(BigInteger id) {
        return t_Account_logMapper.delete(id);
    }

    /**
     * 根据条件统计数据量     *      * @return
     */

    public long count(T_Account_logModel req) {
        return t_Account_logMapper.count(req);
    }

    /**
     * 获取账务明细
     */
    public JsonResult getMyAccountInfo(HttpServletRequest request, CommReq req, String uid) {
        JsonResult js = new JsonResult();
        PageHelper.startPage(req.getPage_index(), req.getPage_size());
        T_Account_logModel t_account_logModel = new T_Account_logModel();
        t_account_logModel.setAccount_no(uid);
        List<AccountLogInfoResp> list = t_Account_logMapper.getMyAccountInfo(t_account_logModel);
        String languageCookie = CookieUtils.getCookie(request, "local");
        String language = "CH";
        if (!StringUtils.isEmpty(languageCookie) && MultiLanguage.acceptLanguages.containsKey(languageCookie))
            language = MultiLanguage.acceptLanguages.get(languageCookie);
        for (AccountLogInfoResp l : list) l.setLanguage(language);
        js.setData(new PageInfo<>(list));
        return js;
    }

    public JsonResult getMyAccountOutTransInfo(HttpServletRequest request, CommReq req, String uid) {
        JsonResult js = new JsonResult();
        PageHelper.startPage(req.getPage_index(), req.getPage_size());
        T_Account_logModel t_account_logModel = new T_Account_logModel();
        t_account_logModel.setAccount_no(uid);
        List<AccountLogInfoResp> list = t_Account_logMapper.getMyAccountOutTransInfo(t_account_logModel);
        String language = CookieUtils.getCookie(request, "local");
        if (!StringUtils.isEmpty(language)) {
            for (AccountLogInfoResp l : list) {
                l.setLanguage("EN");
            }
        }
        js.setData(new PageInfo<>(list));
        return js;
    }
}